/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.client.LmcSession;
/*     */ import com.zimbra.cs.client.soap.LmcDeleteAccountRequest;
/*     */ import com.zimbra.cs.db.DbMailbox;
/*     */ import com.zimbra.cs.db.DbResults;
/*     */ import com.zimbra.cs.db.DbUtil;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.volume.Volume;
/*     */ import com.zimbra.cs.volume.VolumeManager;
/*     */ import java.io.File;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class TestAccount
/*     */   extends TestCase
/*     */ {
/*  45 */   private static String USER_NAME = "TestAccount";
/*  46 */   private static String PASSWORD = "test123";
/*     */   
/*     */   public void setUp() throws Exception
/*     */   {
/*  50 */     cleanUp();
/*     */     
/*  52 */     Map<String, Object> attrs = new HashMap();
/*  53 */     attrs.put("zimbraMailHost", LC.zimbra_server_hostname.value());
/*  54 */     attrs.put("cn", "TestAccount");
/*  55 */     attrs.put("displayName", "TestAccount unit test user");
/*  56 */     Provisioning.getInstance().createAccount(TestUtil.getAddress(USER_NAME), PASSWORD, attrs);
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/*  61 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void testDeleteAccount() throws Exception {
/*  65 */     ZimbraLog.test.debug("testDeleteAccount()");
/*     */     
/*     */ 
/*  68 */     Account account = TestUtil.getAccount(USER_NAME);
/*  69 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/*  70 */     String dbName = DbMailbox.getDatabaseName(mbox);
/*  71 */     ZimbraLog.test.debug("Account=" + account.getId() + ", mbox=" + mbox.getId());
/*     */     
/*     */ 
/*  74 */     DbResults results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId(), new Object[0]);
/*     */     
/*  76 */     assertEquals("Could not find row in mailbox table", 1, results.getInt(1));
/*     */     
/*  78 */     results = DbUtil.executeQuery("SHOW DATABASES LIKE '" + dbName + "'", new Object[0]);
/*  79 */     assertEquals("Could not find mailbox database", 1, results.size());
/*     */     
/*     */ 
/*  82 */     TestUtil.addMessage(mbox, "TestAccount testDeleteAccount");
/*  83 */     String storePath = VolumeManager.getInstance().getCurrentMessageVolume().getMessageRootDir(mbox.getId());
/*  84 */     File storeDir = new File(storePath);
/*  85 */     if (TestUtil.checkLocalBlobs()) {
/*  86 */       assertTrue(storePath + " does not exist", storeDir.exists());
/*  87 */       assertTrue(storePath + " is not a directory", storeDir.isDirectory());
/*     */     }
/*     */     
/*  90 */     LmcSession session = TestUtil.getAdminSoapSession();
/*  91 */     LmcDeleteAccountRequest req = new LmcDeleteAccountRequest(account.getId());
/*  92 */     req.setSession(session);
/*  93 */     req.invoke(TestUtil.getAdminSoapUrl());
/*     */     
/*     */ 
/*  96 */     results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId(), new Object[0]);
/*     */     
/*  98 */     assertEquals("Unexpected row in mailbox table", 0, results.getInt(1));
/*     */     
/* 100 */     if (TestUtil.checkLocalBlobs())
/*     */     {
/* 102 */       assertFalse(storePath + " exists", storeDir.exists());
/*     */     }
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception {
/* 107 */     Provisioning prov = Provisioning.getInstance();
/* 108 */     Account account = prov.get(Key.AccountBy.name, TestUtil.getAddress(USER_NAME));
/* 109 */     if (account != null) {
/* 110 */       prov.deleteAccount(account.getId());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */